package com.lyq.controller;

import com.lyq.mapper.OrderMapper;
import com.lyq.pojo.Order;
import com.lyq.pojo.VO.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyq
 * @since 2020-04-23
 */
@Controller
@RequestMapping("/order")
public class OrderContentController {
    @Autowired
    private OrderMapper orderMapper;

    /**
     * ffindAll
     * @param model
     * @return
     */
    @RequestMapping("/orderList")
    public String orderList(Model model){
        List<OrderVO> orderVOS = orderMapper.selectOrderAll();
        model.addAttribute("orderList",orderVOS);
        return "order/orderList";

    }
    @GetMapping("/toUpdateOrder/{id}")
    public String toUpdateOrder(@PathVariable("id")Integer id,Model model){
        Order order = orderMapper.selectById(id);
        model.addAttribute("order",order);
        return "order/updateOrder.html";
    }
    @PostMapping("updateOrder")
    public String updateOrder(Order order){
        int i = orderMapper.updateById(order);
        return "redirect:/order/orderList";

    }

}

